<template>
  <div v-if="show" class="uni-popup" :class="'uni-popup-' + type" @click="maskClick">
    <div class="uni-popup-content" @click.stop>
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: 'UniPopup',
  props: {
    type: {
      type: String,
      default: 'center'
    }
  },
  data() {
    return {
      show: false
    }
  },
  methods: {
    open() {
      this.show = true
    },
    close() {
      this.show = false
    },
    maskClick() {
      this.close()
    }
  }
}
</script>

<style scoped>
.uni-popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.uni-popup-center {
  align-items: center;
  justify-content: center;
}

.uni-popup-content {
  background: white;
  border-radius: 8px;
  max-width: 90%;
  max-height: 90%;
  overflow: auto;
}
</style>